package a66weding.com.jiehuntong.activity;

import android.app.Activity;
import android.app.Notification;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.w3c.dom.Text;
import org.xutils.view.annotation.Event;

import java.util.HashMap;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.MessageEvent;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;
import a66weding.com.jiehuntong.pager.IContant;

/**
 * Created by admin on 2016/7/12.
 */
public class MoneyActivity extends Activity implements View.OnClickListener,IContant,OnNetResultListener{

    private TextView setting_money_save;
    private EditText setting_money_editext;
    private String content;
    //标题
    private String title;
    private TextView back_iamge;
    private TextView title_tv;
    private String money;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.job_edit_money);
        title = getIntent().getStringExtra(JobDetail.TASK_FLAG);
        money = getIntent().getStringExtra("money");
        initView();
        //setBuget();
    }

    private void initView(){
        setting_money_save = (TextView) findViewById(R.id.activity_notice_done);
        setting_money_save.setOnClickListener(this);
        setting_money_editext = (EditText) findViewById(R.id.local_place_editext);
        back_iamge = (TextView) findViewById(R.id.back_iamge);
        back_iamge.setText(title);
        title_tv = (TextView) findViewById(R.id.title_tv);
        title_tv.setText("消费金额");
        setting_money_editext.setText(money);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        content = setting_money_editext.getText().toString();
        switch (v.getId()){
            case  R.id.activity_notice_done:
                if (content==null||"".equals(content)){
                    CUtils.showToast("你还没输入金额");
                }else{
                    setBuget();
                    Intent intent = new Intent();
                    intent.putExtra(MONEY,content);
                    setResult(4,intent);
                    finish();
                }
                break;
        }
    }

    public  void  setBuget(){
       String useUrl = UrlDealUtil.getRealUrl( RequestCode.UPDATE_BUDGETMONEY);
        HashMap<String,String> paramsMap=new HashMap<>();
        paramsMap.put("BookTitle",title);
        paramsMap.put("BudgetMoney",content);
        HttpRequestBean requestBean = new HttpRequestBean(RequestCode.POSTEQUEST, useUrl, this,CommonResultBean.class, RequestCode.UPDATE_BUDGETMONEY,paramsMap);
        HttpHandleUtil.executeCommonPost(this,requestBean);
    }
    private CommonResultBean been;
    @Override
    public void onSucess(SuccessBean sucessbean) {
        Object data = sucessbean.getData();
        if(data instanceof  CommonResultBean){
            been  = (CommonResultBean) data;
            switch (been.getResCode()){
                case "0000" :
                    CUtils.showToast("修改成功了");
                    break;
            }
        }
    }

    @Override
    public void onError(ErrorBean errorBean) {

    }

    public void back(View view){
        finish();
    }
}
